<template>
  <div class="notifications-page">
    <el-splitter class="chat-splitter">
      <!-- 左侧对象列表 -->
      <el-splitter-panel
        class="chat-object-panel"
        :resizable="false"
        size="22%"
      >
        <div class="chat-object">
          <div class="panel-header">
            <h2>消息中心</h2>
            <el-button type="primary" :icon="Refresh" circle size="small" />
          </div>
          
          <div class="search-container">
            <el-input
              placeholder="搜索消息..."
              :prefix-icon="Search"
              size="large"
              clearable
            />
          </div>
          
          <div class="category-section">
            <p class="category-title">
              <el-icon><ChatDotRound /></el-icon>
              系统消息
            </p>
            <chat-object
              :active="activeChat === 'system'"
              img=""
              name="系统消息"
              lastMessage="欢迎使用水晶战争游戏平台！"
              timestamp="刚刚"
              unread-count="2"
              @click="setActiveChat('system')"
            />
            <chat-object
              :active="activeChat === 'service'"
              img=""
              name="智能客服"
              lastMessage="您好,我是智能客服,有什么可以帮您？"
              timestamp="刚刚"
              @click="setActiveChat('service')"
            />
            <chat-object
              :active="activeChat === 'interaction'"
              img=""
              name="互动信息"
              lastMessage="有人评论了你的帖子"
              timestamp="2分钟前"
              unread-count="5"
              @click="setActiveChat('interaction')"
            />
          </div>
          
          <div class="category-section">
            <p class="category-title">
              <el-icon><User /></el-icon>
              用户消息
            </p>
            <chat-object
              :active="activeChat === 'user1'"
              img=""
              name="浪兎兎"
              lastMessage="浪兎兎是大帅比"
              timestamp="10:30"
              unread-count="1"
              @click="setActiveChat('user1')"
            />
            <chat-object
              :active="activeChat === 'user2'"
              img=""
              name="森森森RE"
              lastMessage="浪兎兎是大傻子"
              timestamp="昨天"
              @click="setActiveChat('user2')"
            />
          </div>
        </div>
      </el-splitter-panel>
      
      <!-- 右侧聊天窗口 -->
      <el-splitter-panel class="chat-window-panel" :resizable="false">
        <div class="chat-window">
          <div class="chat-header">
            <div class="chat-info">
              <el-avatar :icon="UserFilled" size="large" :style="{ backgroundColor: activeChatConfig.color }" />
              <div class="chat-details">
                <span class="chat-title">{{ activeChatConfig.title }}</span>
                <span class="chat-status">在线</span>
              </div>
            </div>
            <div class="header-actions">
              <el-button :icon="Phone" circle />
              <el-button :icon="VideoCamera" circle />
              <el-button :icon="More" circle />
            </div>
          </div>
          
          <div class="chat-messages">
            <div class="message-date-divider">
              <span>今天</span>
            </div>
            
            <div class="message message-system">
              <el-avatar :icon="UserFilled" :style="{ backgroundColor: '#2196F3' }" />
              <div class="message-content-wrapper">
                <div class="message-content">欢迎使用水晶战争游戏平台！</div>
                <div class="message-time">10:28</div>
              </div>
            </div>
            
            <div class="message message-user">
              <div class="message-content-wrapper">
                <div class="message-content">谢谢！这个平台太棒了！</div>
                <div class="message-time">10:30</div>
              </div>
            </div>
            
            <div class="message message-system">
              <el-avatar :icon="UserFilled" :style="{ backgroundColor: '#2196F3' }" />
              <div class="message-content-wrapper">
                <div class="message-content">很高兴您喜欢！如有任何问题，请随时联系我们。</div>
                <div class="message-time">10:32</div>
              </div>
            </div>
          </div>
          
          <div class="chat-input-bar">
            <div class="input-actions">
              <el-button :icon="Plus" circle text />
              <el-button :icon="Picture" circle text />
              <el-button :icon="Folder" circle text />
            </div>
            <el-input
              v-model="inputMessage"
              placeholder="输入消息..."
              clearable
              @keyup.enter="sendMessage"
              size="large"
              class="chat-input"
            />
            <el-button 
              type="primary" 
              @click="sendMessage" 
              class="chat-send-btn"
              :icon="Promotion"
              :disabled="!inputMessage.trim()"
            >
              发送
            </el-button>
          </div>
        </div>
      </el-splitter-panel>
    </el-splitter>
  </div>
</template>

<script setup lang="ts">
import { ref, reactive, computed } from "vue";
import { useHead } from "nuxt/app";
import { 
  UserFilled, 
  Search, 
  Refresh, 
  Phone, 
  VideoCamera, 
  More, 
  Plus, 
  Picture, 
  Folder, 
  Promotion,
  ChatDotRound,
  User
} from "@element-plus/icons-vue";

useHead({
  title: "消息通知 - 水晶战争游戏平台",
});

const inputMessage = ref("");
const activeChat = ref("system");

const chatConfigs = {
  system: { title: "系统消息", color: "#2196F3" },
  service: { title: "智能客服", color: "#4CAF50" },
  interaction: { title: "互动信息", color: "#FF9800" },
  user1: { title: "浪兎兎", color: "#E91E63" },
  user2: { title: "森森森RE", color: "#9C27B0" }
};

const activeChatConfig = computed(() => {
  return chatConfigs[activeChat.value as keyof typeof chatConfigs] || chatConfigs.system;
});

function setActiveChat(chat: string) {
  activeChat.value = chat;
}

function sendMessage() {
  if (!inputMessage.value.trim()) return;
  // 这里可以添加消息到聊天记录
  inputMessage.value = "";
}
</script>

<style scoped>
.notifications-page {
  height: 100vh;
  background: linear-gradient(135deg, #f5f7fa 0%, #e4e7ed 100%);
  padding: 16px;
}

.chat-splitter {
  height: calc(100vh - 32px);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
  height: 850px;
}

.chat-object-panel {
  background: #fff;
  display: flex;
  flex-direction: column;
}

.chat-window-panel {
  background: #fff;
  display: flex;
}

.chat-object {
  height: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px 16px 10px;
  border-bottom: 1px solid #f0f0f0;
}

.panel-header h2 {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
  color: #1f2d3d;
}

.search-container {
  padding: 16px;
  border-bottom: 1px solid #f0f0f0;
}

.category-section {
  padding: 8px 0;
}

.category-title {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  margin: 0;
  color: #606266;
  font-size: 13px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.chat-window {
  height: 100%;
  display: flex;
  flex-direction: column;
  background: #f7f9fa;
}

.chat-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 24px;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
  z-index: 1;
}

.chat-info {
  display: flex;
  align-items: center;
  gap: 12px;
}

.chat-details {
  display: flex;
  flex-direction: column;
}

.chat-title {
  font-size: 16px;
  font-weight: 600;
  color: #1f2d3d;
}

.chat-status {
  font-size: 12px;
  color: #67c23a;
}

.header-actions {
  display: flex;
  gap: 8px;
}

.header-actions .el-button {
  border: none;
  background: #f5f7fa;
}

.chat-messages {
  flex: 1;
  padding: 24px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.message-date-divider {
  display: flex;
  justify-content: center;
  margin: 16px 0;
}

.message-date-divider span {
  background: #e4e7ed;
  color: #606266;
  padding: 4px 12px;
  border-radius: 12px;
  font-size: 12px;
}

.message {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  max-width: 75%;
}

.message-system {
  align-self: flex-start;
}

.message-user {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.message-content-wrapper {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.message-content {
  background: #fff;
  padding: 12px 16px;
  border-radius: 8px;
  font-size: 14px;
  color: #1f2d3d;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.05);
  line-height: 1.5;
  position: relative;
}

.message-system .message-content {
  border-top-left-radius: 0;
  background: #fff;
  border: 1px solid #e4e7ed;
}

.message-user .message-content {
  background: #d0e8ff;
  border-top-right-radius: 0;
}

.message-time {
  font-size: 11px;
  color: #909399;
  padding: 0 4px;
}

.chat-input-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 24px;
  background: #fff;
  box-shadow: 0 -1px 3px rgba(0, 0, 0, 0.05);
}

.input-actions {
  display: flex;
  gap: 4px;
}

.input-actions .el-button {
  border: none;
  color: #606266;
}

.chat-input {
  flex: 1;
}

.chat-input :deep(.el-input__wrapper) {
  border-radius: 20px;
  background: #f5f7fa;
  box-shadow: none;
  padding: 2px 16px;
}

.chat-send-btn {
  border-radius: 20px;
  padding: 10px 20px;
}

.chat-send-btn:disabled {
  opacity: 0.6;
}
</style>